package io.gitee.yanbinchen;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @author: alex
 * @since : 2025-03-04 19:35
 */
@Aspect
@Component
@Order(1)
public class DelSuperCacheAspect extends AbstractSuperCache {
    @Autowired
    SuperCacheService superCacheService;

    @Before("@annotation(io.gitee.yanbinchen.DelSuperKey)")
    public void around(JoinPoint joinPoint) throws Throwable {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        DelSuperKey delSuperKey = method.getAnnotation(DelSuperKey.class);
        String cacheKey = getCacheKey(delSuperKey, ((MethodSignature) joinPoint.getSignature()).getMethod(), joinPoint.getArgs());
        superCacheService.unlink(cacheKey);
    }
}
